<template>
  <a-modal
    title="创建商户等级限额管理"
    v-model="show"
    :maskClosable="false"
    :width="1050"
    placement="right"
    :closable="true"
    @cancel="onClose"
    :footer="null"
    :visiable="merchantGradeManagerAddVisiable"
  >
    <a-form :form="form">
      <a-row>新增限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="商户等级"
                       v-bind="formItemLayout">
            <a-select
              show-search
              placeholder="请输入代码或名称"
              option-filter-prop="children"
              style="width: 334px"
              :filter-option="filterOption"
              @focus="selectMchntNo"
              @search="selectMchntNo"
              v-decorator="['mchntLevelCode',{rules: [{ required: true, message: '必填字段'}]}]">
              <a-select-option v-for="(d,index) in grpNoData" :key="d.mchntLevelCode">
                {{d.mchntLevelCode}}-{{ d.mchntLevelName }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label="日累计限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['dayLimitAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label='单笔限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['singleLimitMaxAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='月累计限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['monthLimitAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>借记限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="单笔借记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['singleLimitLoanMaxAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='日累计借记限额'
                       v-bind="formItemLayout">
            <a-input placeholder="小微商户必填最大1000" v-decorator="['dayLimitLoanAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="月累计借记限额"
                       v-bind="formItemLayout">
            <a-input placeholder="小微商户必填最大1000" v-decorator="['monthLimitLoanAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row>贷记限额</a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="单笔贷记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['singleLimitCreditMaxAmt']"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item label='日累计贷记限额'
                       v-bind="formItemLayout">
            <a-input v-decorator="['dayLimitCreditAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item label="月累计贷记限额"
                       v-bind="formItemLayout">
            <a-input v-decorator="['monthLimitCreditAmt']"/>
          </a-form-item>
        </a-col>
      </a-row>

      <br>

    </a-form>

    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="onClose" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="loading">提交</a-button>
    </div>
  </a-modal>

</template>
<script>
  const formItemLayout = {
    labelCol: {span: 8},
    wrapperCol: {span: 16}
  }
  export default {
    name: 'MerchantGradeManagerAdd',

    props: {
      merchantGradeManagerAddVisiable: {
        default: false
      },
      instId: '',
    },
    data() {
      return {
        data: [],
        grpNoData: [],
        mchntNoLevelInfo: {
          visiable: false
        },
        loading: false,
        formItemLayout,
        form: this.$form.createForm(this),
        validateStatus: '',
        // firstValue: {},
        info: {
          infoName: '',
          remark: '',
          menuId: ''
        }
      }
    },
    computed: {
      show: {
        get: function () {
          return this.merchantGradeManagerAddVisiable
        },
        set: function () {
        }
      }
    },
    mounted() {

    },

    methods: {

      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },


      selectMchntNo(val) {
        this.grpNoData = []
        let param = {}
        param.instId = this.instId
        this.$get('/admin/quota/merchantGradeManager/getAddMerLevelInfos', param).then((r) => {
          console.log(r.data,'============')

          if (r.data.code == '100000'){
            let result = r.data.data
            console.log(r.data,'dsd==')
            result.forEach(r => {
              this.grpNoData.push(r);
            })
          } else {
            this.$message.error(r.data.message)
          }
        })
      },

      reset() {
        this.loading = false
        this.form.resetFields()
      },
      onClose() {
        this.reset()
        this.$emit('close')
      },
      handleSubmit() {
        this.form.validateFields((err, values) => {
            this.setInfoFields()
            this.loading = true
            this.info.instId = this.instId
            this.info.optFlag = 'add'
            // console.log(this.info)
            this.$post('/admin/quota/merchantGradeManager/saveMerGradeQuota', {
              ...this.info
            }).then((r) => {
              if (r.data.code!="100000"){
                this.loading = false
                this.$message.error(r.data.message)
              }else {
                this.reset()
                this.$emit('success')
              }
            })

        })

      },

      setInfoFields() {
        let values = this.form.getFieldsValue(['grpNo', 'mchntLevelCode','industryType', 'dayLimitAmt', 'monthLimitAmt', 'singleLimitLoanMaxAmt',
          'dayLimitLoanAmt', 'monthLimitLoanAmt', 'singleLimitCreditMaxAmt', 'dayLimitCreditAmt', 'monthLimitCreditAmt'])
        if (typeof values !== 'undefined') {
          Object.keys(values).forEach(_key => {
            this.info[_key] = values[_key]
          })
        }
      },


    },

  }
</script>


